//可接受三个参数
let mySetTimeOut = (fn, timeout, ...args) =>{
    //初始化当前时间
    const start = +new Date();

    let timer, now;
    const loop = () => {
        timer = window.requestAnimationFrame(loop);
        now = +new Date();
        if(now - start >= timeout){
            console.log(this);
            fn.apply(this, args);
            window.cancelAnimationFrame(timer);
        }
    }

    //通过调用一个浏览器的线程 而不是 js的主线程来实现异步非阻塞
    window.requestAnimationFrame(loop);
    
}